package 一些算法竞赛测试题;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: a
 * Date: 2022-10-08
 * Time: 14:20
 */

//赢球票
public class Demo10 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] q = new int[n];
        int[] p = new int[n];
        int res = 0;
        for(int i = 0; i < n; i++){
            q[i] = scan.nextInt();
        }
        for(int i = 0; i < n; i++){
            int sum = 0;
            for(int j = 0; j < n; j++){
                p[j] = q[j];
            }
            int k = i;
            for(int j = 1; j <= n; j++){
                if(p[k] == 0){
                    int z = 0;
                    for(z = 0; z < n; z++){
                        if(p[z] != 0){
                            break;
                        }
                    }
                    if(z == n){
                        break;
                    }
                    j--;
                }else if(p[k] == j){
                    sum += p[k];
                    p[k] = 0;
                    j = 0;
                }
                k++;
                if(k == n){
                    k = 0;
                }
            }
            res = Math.max(res, sum);
        }
        System.out.println(res);
    }
}
